package club.koorilkaze.dbc;

import club.koorilkaze.util.JdbcUtils;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @program: SQLconnDAO
 * @description: 负责数据库的连接和关闭
 * @author: Hermit_Yoshino
 * @create: 2019-07-24 16:29
 **/
public class DatabaseConnection {

    private DriverManager driverManager = null;
    private Connection connection = null;

    public DatabaseConnection () throws SQLException {
        connection = JdbcUtils.dbConnection();
    }
    
    /** 
     * @Description: 获取 Connection 对象
     * @param: []
     * @author: Hermit_Yoshino
     * @date: 2019/7/24 19:03
     * @throws: Exception
     * @return: java.sql.Connection 
     * @version: 0.0.1
     */ 
    public Connection getConnection() {
        return connection;
    }

    /** 
     * @Description: 关闭 Connection
     * @param: [] 
     * @author: Hermit_Yoshino
     * @date: 2019/7/24 19:04
     * @throws: Exception
     * @return: void 
     * @version: 0.0.1
     */ 
    public void close() throws SQLException {
        if ( this.connection != null ) {
            try {
                connection.close();
            } catch (SQLException e) {
                throw e;
            }
        }
        return;
    }
}
